﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.OleDb;
using System.IO;

namespace DbTask
{
  /// <summary>
  /// Data Access Class for application
  /// </summary>
  public class DataAccess
  {
    protected OleDbConnection myConnection;

    public DataAccess()
    {
        //Retrieves database connection string
        myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
    }

    //Execute and return Datatable by sql string
    public DataTable ExecuteSQL(string sql)
    {
      DataTable da = new DataTable();
      OleDbCommand myCommand = new OleDbCommand(sql, myConnection);
      myCommand.CommandType = CommandType.Text;

      try
      {
          OleDbDataAdapter ad = new OleDbDataAdapter(myCommand);
          ad.Fill(da);
      }
      catch (Exception ex)
      {
          throw ex;
      }

      return da;
    }// End ExecuteSQL
  }//End DataAccess
}